/// 
/// Author: Jeff Liu
/// Date: 2021-11-29 16:50:09
/// LastEditTime: 2021-11-29 16:50:34
/// LastEditors: Jeff Liu
/// Description: 
/// FilePath: /hcc/Users/jiliu/Library/Caches/com.lemonmojo.RoyalTSX.App/LMFileTransferConnection/3538fa5b-6d01-4952-a049-ac116199c617/L2lzYy9oY2MtbWFpbi9zcmMvV1MvREU=/Base.cls
/// Jeff.liu@intersytems.com
/// 
/// Author: QP
/// Version: 1.0
/// Date: 2021/07/04
/// 卫生数据元基类
Class WS.DE.Base Extends (%SerialObject, %XML.Adaptor, %JSON.Adaptor) [ Abstract, Language = objectscript, Not ProcedureBlock, System = 3 ]
{

/// 数据集
Parameter Category;

/// 数据元代码
Parameter Code;

/// 数据元描述
Parameter Description;

/// 数据元格式
Parameter Format;

/// 值集
Parameter ValueSet;

/// 值集显示值
Parameter ValueSetDisplay;

/// 数据元数据类型
Parameter WSDT;

/// 数据元xsi数据类型
Parameter XSIDT;

/// 数据元内部标识符
/// Parameter InternalID;
/// Code System
Parameter CodeSystem = "2.16.156.10011.2.2.1";

/// Code System Name
Parameter CodeSystemName = "卫生信息数据元目录";

// Property Value As %DataType;

Property DE As %DataType [ Calculated ];

Method DEGet() As %Library.String
{
    Set tTmp=..%ClassName(0)
    Quit $E(tTmp,1,4)_"."_$E(tTmp,5,6)_"."_$E(tTmp,7,9)_"."_$E(tTmp,10,11)
}

Property Display As %DataType [ Calculated ];

Method DisplayGet() As %Library.String
{
    Quit ##class(WS.DE.Tools).GetValueSetDisplay(..%ClassName(1),..Value)
}

Property codeSystem As %DataType [ Calculated ];

Method codeSystemGet() As %Library.String
{
    Quit ..#CodeSystem
}

Property codeSystemName As %DataType [ Calculated ];

Method codeSystemNameGet() As %Library.String
{
    Quit ..#CodeSystemName
}

Property code As %DataType [ Calculated ];

Method codeGet() As %Library.String
{
    Quit ..#Code
}

Property displayName As %DataType [ Calculated ];

Method displayNameGet() As %Library.String
{
    Quit ..#Description
}

/// 设置对象的Modified标志，从而强制类型校验
/// 模版方法
Method SetModified() As %Status [ CodeMode = objectgenerator, ForceGenerate ]
{
    // 不处理基类
    Quit:%classname="HCC.SQL.Base" $$$OK
    // 不处理以下属性
    Do %code.WriteLine(" Set tSC=1")
    Do %code.WriteLine(" Try ")
    Do %code.WriteLine(" { ")
    Do %code.WriteLine("    Do $system.CLS.SetModified(##this, 1)")
    For n=1:1:%compiledclass.Properties.Count()
    {
        Set tPropDef = %compiledclass.Properties.GetAt(n)
        
        //不处理计算属性、多维属性 
        Set tNotProcess = tPropDef.Calculated||(tPropDef.MultiDimensional)||((tPropDef.Transient)&&(tPropDef.Cardinality=""))||($E(tPropDef.Name,1,2)="%%")
        Continue:(tNotProcess)
        
        Set tPropType = tPropDef.Type,tClassType=""
        
        Set tClassType = ##class(WS.DE.Tools).GetClassType(tPropType)
        If tClassType="serial"
        {
            Do %code.WriteLine("    do .."_tPropDef.Name_".SetModified()")
        }
    }
    Do %code.WriteLine("    Return tSC")
    Do %code.WriteLine(" }")
    Do %code.WriteLine(" catch e")
    Do %code.WriteLine(" {")
    Do %code.WriteLine("    Set tSC = $$$ERROR(e.Code,e.Data)")
    Do %code.WriteLine(" }")
    Do %code.WriteLine(" Quit tSC")
    Quit $$$OK
}


}
